package com.agan.aganjavaspyder.crawler.un_demo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpPostRequest;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cglovewx
 */
@PipelineName("UNPhonePipeline")
@Slf4j
public class UNPhonePipeline implements Pipeline<StartCtPhone> {

	@SneakyThrows
	@Override
	public void process(StartCtPhone startCtPhone) {

		log.info("首页url整合处理"+startCtPhone.getTotalSize());
		for (String  href :startCtPhone.getResultText()){
			System.out.println("1 href:-----"+href);
			//继续抓取详情页
			HttpRequest sub = startCtPhone.getRequest().subRequest(href);
			SchedulerContext.into(sub);
			Thread.sleep(1000);
			break;

		}
/*		//第二页之后的
		String url = "http://s.10010.com/SearchApp/chseSearchList/refresh?1";
		HttpPostRequest req = new HttpPostRequest();
		Map<String, String> fields = new HashMap<>();
		fields.put("serAttrs", "pc_s:1");
		fields.put("keyword",startCtPhone.getKeyword());
		fields.put("categories","");
		fields.put("sortMode","salesVolume");
		fields.put("page.webPager.action","2");
		fields.put("page.webPager.pageInfo.totalSize","95");
		fields.put("page.webPager.currentPage","1");
		//fields.put("timeStamp", DateUtil.format(new Date(),PURE_DATETIME_PATTERN));
		fields.put("timeStamp","20201015013529");
		req.setFields(fields);
		req.setUrl(url);
		SchedulerContext.into(req);*/



	}



}